package com.oak.consumerhystrix80;

import com.netflix.hystrix.contrib.javanica.annotation.DefaultProperties;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixProperty;
import com.oak.consumerhystrix80.OpenFeignService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * com.oak.consumer -> ConsumerController
 *
 * @Author: guoxy
 * @Description:
 * @Date: 2022/5/15
 */
@RestController
@DefaultProperties(defaultFallback = "defaultTimeOut")
public class ConsumerController {


    @Autowired
    private OpenFeignService openFeignService;

    /**
     * 使用openfeign调用服务
     *
     * @return
     */
    @GetMapping("/getOrderOpenFeign")
    private String getOrderOpenFeign() {
        return openFeignService.orderServer();
    }

    @GetMapping("/timeOutOpenFeign")
    @HystrixCommand(fallbackMethod = "defaultTimeOut",commandProperties = {
            @HystrixProperty(name = "execution.isolation.thread.timeoutInMilliseconds",value = "1000")
    })    private String timeOut() {
        return openFeignService.timeOut();
    }


    public String defaultTimeOut() {
        return "GlobalFallBack全局降级，系统繁忙请稍后再试timeOut！";
    }
}